package org.magicbox.qjunTPO.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.magicbox.qjunTPO.common.lang.Result;
import org.magicbox.qjunTPO.entity.CommentUser;
import org.magicbox.qjunTPO.service.CommentUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author 欢迎添加科技实践队粉丝群：690849711
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/comment-user")
public class CommentUserController {
    @Autowired
    CommentUserService cuService;

    /**
     * 获取20条一级评论,时间拉排序
     * @param poemId    文章id
     * @param pageNumber    评论页码
     * @return          20条评论
     */
    @RequestMapping("/equryTime/{poem_id}/{pageNumber}")  //
    public Result equry_time(@PathVariable("poem_id")Integer poemId, @PathVariable("pageNumber")Integer pageNumber){
        //获取评论和评论者头像和网名
        Page page =new Page(pageNumber,3);
//        Map<String,Integer> poemMap = new HashMap<String,Integer>();
//        poemMap.put("poem_id",poemId);
        IPage pageData =cuService.page(page,new QueryWrapper<CommentUser>().eq("poem_id",poemId).isNull("precursors").orderByDesc("comment_create"));

        return Result.success(pageData);
    }

    /**
     * 获取20条一级评论,点赞拉排序
     * @param poemId 文章id
     * @param pageNumber    页码
     * @return  20条评论
     */
    @RequestMapping("/equryLike/{poem_id}/{pageNumber}")  //
    public Result equry_like(@PathVariable("poem_id")Integer poemId, @PathVariable("pageNumber")Integer pageNumber){
        //获取评论和评论者头像和网名
        Page page =new Page(pageNumber,20);
        Map<String,Integer> poemMap = new HashMap<String,Integer>();
        poemMap.put("poem_id",poemId);
        IPage pageData =cuService.page(page,new QueryWrapper<CommentUser>().allEq(poemMap).orderByDesc("like_sum"));

        return Result.success(pageData);
    }

}
